/**
 * Created by shbs on 04/07/2017.
 */
import axios from 'axios'
import router from "../router"
var querystring = require('querystring');
axios.defaults.timeout = 5000;
//axios.defaults.baseURL="http://192.168.1.102:8080/dianmi_service/";
axios.defaults.baseURL="/brand_service/";
axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded';

// http请求拦截
axios.interceptors.request.use(config => {

    if(config.data){
        config.data=querystring.stringify(config.data);
    }
    return config
}, error => {

    return Promise.reject(error)
});
// http响应拦截器
axios.interceptors.response.use(res => {
    if(res.config.url.indexOf('getUserMapBySeesion')>0){
        return res;
    }
    if (res.data.message=="noueser"){
        vm.$notify.error({
            title: '错误',
            message: '未登录或登录超时,请重新登录'
        });
        router.push({
            name:"登录"
        })
    }
    return res
}, error => {
    vm.$notify.error({
        title: '错误',
        message: '请求失败'
    });
    //return Promise.reject(error)
});
export default {
    /**
     * 登录
     * @param params {object} 格式：{username:xxx, password:xxx}
     */
    axios:axios,
    login: (params) => axios.post("/login.action", params),
    getUserMapBySeesion: () => axios.post("/getUserMapBySeesion.action"),
    addProject: (params) => axios.post("/addProject.action",params),
    searchProjectList: (params) => axios.post("/searchProjectList.action",params),//查询商品列表
    searchProductDetail: (params) => axios.post("/searchProductDetail.action",params),//根据商品编号查询商品详情信息
    updateProductByCode: (params) => axios.post("/updateProductByCode.action",params),//商品修改
    uploadLunboImg: (params) => axios.post("/uploadLunboImg.action",params),//上传商品单个图片
    updateProductShelvesByCode: (params) => axios.post("/updateProductShelvesByCode.action",params),//修改商品上架状态
    updateProductAuditByCode: (params) => axios.post("/updateProductAuditByCode.action",params),//商品提交审核
    orderSearch: (params) => axios.post("/orderSearch.action",params),//订单列表查询
    orderDetailByCode: (params) => axios.post("/orderDetailByCode.action",params),//订单详情
    updateOrderState: (params) => axios.post("/updateOrderState.action",params),//修改订单状态（发货）
    AddFranchise: (params) => axios.post("/AddFranchise.action",params),//品牌商添加加盟商
    queryFranchiseUser: (params) => axios.post("/queryFranchiseUser.action",params),//品牌商查询加盟商用户列表
    querybrandstore: (params) => axios.post("/querybrandstore.action",params),//查询品牌商详情


    login_out: () => axios.post("/login_out.action"),//退出登陆
    searchComProjectList: (params) => axios.post("/searchComProjectList.action",params),//查询公共区商品
    updatePublicProductByCode: (params) => axios.post("/updatePublicProductByCode.action",params),//修改公共区商品
    updateUserPass: (params) => axios.post("/updateUserPass.action",params),//修改登录密码
    updbrandstore: (params) => axios.post("/updbrandstore.action",params),//修改加盟商信息
}
